package main

import (
	"math"
)

func largestValues(root *TreeNode) []int {
	var queue []*TreeNode
	res := make([]int, 0)
	if nil != root {
		queue = append(queue, root)
	}
	for len(queue) > 0 {
		l := len(queue)
		max := math.MinInt
		for i := 0; i < l; i++ {
			v := queue[0]
			if v.Val >= max {
				max = v.Val
			}
			queue = queue[1:]
			if nil != v.Left {
				queue = append(queue, v.Left)
			}
			if nil != v.Right {
				queue = append(queue, v.Right)
			}
		}
		res = append(res, max)
	}
	return res
}

func main() {

}
